package com.teemor;

/**
 * @author zhoulike
 * @date 2024/7/9 14:55
 */
public class Message {
    private long timestamp;

    private Type type;

    private int sendId;

    private int receiveId;

    private Object data;

    public enum Type{
        /**
         * 消息类型
         */
        HEARTBEAT,
        ELECTION,
        ELECTION_RESULT,
        VOTE,
        APPEND_ENTRIES,
        REQUEST_VOTE,
        REQUEST_V
    }

    public Message(Type type, int sendId, int receiveId, Object data) {
        this.timestamp = System.currentTimeMillis();
        this.type = type;
        this.sendId = sendId;
        this.receiveId = receiveId;
        this.data = data;
    }

    public static class ElectionMessage {
        /**
         * 投票轮次
         */
        private int term;

        /**
         * 投票结果
         */
        private int result;

        public ElectionMessage(int term, int result) {
            this.term = term;
            this.result = result;
        }

        public int getTerm() {
            return term;
        }

        public void setTerm(int term) {
            this.term = term;
        }

        public int getResult() {
            return result;
        }

        public void setResult(int result) {
            this.result = result;
        }
    }


    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public int getSendId() {
        return sendId;
    }

    public void setSendId(int sendId) {
        this.sendId = sendId;
    }

    public int getReceiveId() {
        return receiveId;
    }

    public void setReceiveId(int receiveId) {
        this.receiveId = receiveId;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
